package mn.slide.labmed.adapter;

import java.util.ArrayList;

import mn.slide.labmed.R;
import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class MyArrayAdapter extends ArrayAdapter<String>
{
	private final Activity			context;
	private final ArrayList<String>	names;

	public MyArrayAdapter( Activity context , ArrayList<String> names )
	{
		super(context , R.layout.row , names);
		this.context = context;
		this.names = names;
	}

	static class ViewHolder
	{
		public TextView	textView;
	}

	@Override
	public View getView( final int position , View convertView , ViewGroup parent )
	{
		ViewHolder holder;
		View rowView = convertView;
		if (rowView == null)
		{
			LayoutInflater inflater = context.getLayoutInflater();
			rowView = inflater.inflate(R.layout.row, null, true);
			holder = new ViewHolder();
			notifyDataSetChanged();
			holder.textView = (TextView) rowView.findViewById(R.id.label);
			rowView.setTag(holder);
		}
		else
		{
			holder = (ViewHolder) rowView.getTag();
		}
		rowView.setBackgroundResource(R.drawable.row_background);
		holder.textView.setText(names.get(position));
		return rowView;
	}

}